<?php

namespace App\Http\Controllers\Admin;

use App\Exceptions\AppException;
use App\Models\Danmu;
use App\Models\Data;
use App\Models\Member;
use App\Models\Prefix;
use App\Services\ExcelExportService;
use Illuminate\Http\Request;

class DataController extends BaseController {

    public function uploadImg(Request $request)
    {
        $rule = ['jpg', 'png', 'gif'];
        $file = $request->file('file');
        $ext = $file->getClientOriginalExtension();//返回上传文件的扩展名称
        if (!in_array($ext, $rule)) {
            return $this->errorCode('10001', [], '图片格式为jpg,png,gif');
        }
        $file->getClientOriginalName();//返回上传文件的真实名称
        $file->getClientSize();//返回上传文件的大小
        $filename=date('ymdHis').time().'.'.$ext;
        // echo $filename;die;
        $result = $file->move('uploads/title',$filename);
        return $this->success(['path' => 'uploads' . '/title/'.$filename], '上传成功');
    }

    public function uploadVideo(Request $request)
    {
        $rule = ['jpg', 'png', 'gif'];
        $file = $request->file('file');
        $ext = $file->getClientOriginalExtension();//返回上传文件的扩展名称
        // if (!in_array($ext, $rule)) {
        //     return $this->errorCode('10001', [], '图片格式为jpg,png,gif');
        // }
        $file->getClientOriginalName();//返回上传文件的真实名称
        $file->getClientSize();//返回上传文件的大小
        $filename=date('ymdHis').time().'.'.$ext;
        // echo $filename;die;
        $result = $file->move('uploads/video',$filename);
        return $this->success(['path' => 'uploads' . '/video/'.$filename], '上传成功');
    }

}